//
//  STThemeSetViewController.m
//  STBasicsApp
//
//  Created by jerry on 2019/5/6.
//  Copyright © 2019 jerry. All rights reserved.
//

#import "STThemeSetViewController.h"
#import "STThemeItemModel.h"
#import "STComTableViewCell.h"

@interface STThemeSetViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic , strong) UITableView * tableView;
@property (nonatomic , strong) NSMutableArray<STThemeItemModel *> * dataArrs;

@end

@implementation STThemeSetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configNav];
    [self showView];
    [self initData];
}

- (void)configNav{
    self.title = ASLocalizedString(@"主题管理");
}

- (void)showView{
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
        make.bottom.equalTo(self.view.mas_bottom);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
    }];
    
}

- (void)initData{
    
    STThemeItemModel * item01 = [[STThemeItemModel alloc]init];
    item01.colorName = @"日间";
    
    STThemeItemModel * item02 = [[STThemeItemModel alloc]init];
    item02.colorName = @"夜晚";
    
    STThemeItemModel * item03 = [[STThemeItemModel alloc]init];
    item03.colorName = @"红色";
    
    STThemeItemModel * item04 = [[STThemeItemModel alloc]init];
    item04.colorName = @"绿色";
    
    STThemeItemModel * item05 = [[STThemeItemModel alloc]init];
    item05.colorName = @"黄色";
    
    [self.dataArrs removeAllObjects];
    [self.dataArrs addObject:item01];
    [self.dataArrs addObject:item02];
    [self.dataArrs addObject:item03];
    [self.dataArrs addObject:item04];
    [self.dataArrs addObject:item05];
    
}

#pragma mark - set/get

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]init];
        _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
        _tableView.dk_separatorColorPicker = DKColorPickerWithKey(TABLEBGSEPARATOR);
        //_tableView.separatorStyle = UITableViewCellSelectionStyleNone;
        _tableView.rowHeight = 44;
        _tableView.dk_backgroundColorPicker = DKColorPickerWithKey(TABLEBG);
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

- (NSMutableArray *)dataArrs{
    if (!_dataArrs) {
        _dataArrs = [[NSMutableArray alloc]init];
    }
    return _dataArrs;
}

#pragma mark - UITableViewDelegate/UITableViewDataSource

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat height = 44.0f;
    return height;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        self.dk_manager.themeVersion = DKThemeVersionNormal;
    }else if (indexPath.row == 1){
        self.dk_manager.themeVersion = DKThemeVersionNight;
    }else if (indexPath.row == 2){//红色
        self.dk_manager.themeVersion = @"RED";
    }else if (indexPath.row == 3){//绿色
        self.dk_manager.themeVersion = @"GREEN";
    }else if (indexPath.row == 4){//黄色
        self.dk_manager.themeVersion = @"YELLOW";
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArrs ? self.dataArrs.count : 0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    STThemeItemModel * itemModel = [self.dataArrs objectAtIndex:indexPath.row];

    static NSString *ID = @"UITableViewCell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.dk_backgroundColorPicker = DKColorPickerWithKey(TABLECELLBG);
    cell.textLabel.dk_textColorPicker = DKColorPickerWithKey(SETTINGMAINTEXT);
    
    if (itemModel) {
        NSString * colorName = itemModel.colorName ? itemModel.colorName : @"";
        cell.textLabel.text = ASLocalizedString(colorName);
    }
    
    return cell;
}


@end
